
#ifndef _LUA_SCRIPT_H_
#define _LUA_SCRIPT_H_

#include "script/IScript.h"
#include "config.h"

struct lua_State;

namespace KCore
{
	typedef int (*lua_func)(lua_State*);
	class _KExport LuaScript : public IScript
	{
	public:
		LuaScript():IScript(),_lState(0)
		{
		}

		~LuaScript();

		 Type getType(){return LUA;}
		 void cleanup();
		 void setup();

		 void loadScript( const char* filename);
		 void loadScript(const char* chunk,size_t size) ;
		
		 void loadString(const char* cmd);
		 void doString(const char* cmd) ;
		
		 void regFunc(const char* funcName,void* func) ;
		 void runScript() ;
		 int callFunction(const char *func, const char *sig, ...) ;
		 void addStringGlobal(const char* name,const char* value) ;
		 void addNumberGlobal(const char* name,double value) ;
		 const char* getStringGlobal(const char* name) ;
		 double getNumberGlobal(const char* name) ;
		 bool getBoolGlobal( const char* aName );
		 void addStringGlobalToTable(const char* tableName,const char* name,const char* value) ;
		 void addNumberGlobalToTable(const char* tableName,const char* name,double value) ;
		
		 const char* getStringGlobalFromTable(const char* tableName,const char* name) ;
		 const char* getStringGlobalFromTable(const char* aTable,int index ) ;

		 double getNumberGlobalFromTable( const char* tableName,const char* aName) ;
		 bool globalExists(const char* name) ;

		 bool globalExistsInTable( const char* tableName,const char* name) ;
		 bool globalExistsInTable( const char* tableName,const int index) ;

		 const char* stackDump() ;

		 void setGlobal(const char* name,void* p);
		 void* getGlobal(const char* name);
	protected:
		 lua_State* _lState;
	};

	_KExport int lua2c_regist_funcs(lua_State* L);
};

#endif

